package org.zjt.review;
import scala.util.control._


/**
 * DESC
 *
 * @author
 * @create 2017-06-20 下午5:55
 **/
object LoopTest extends App{


  //a与b的笛卡尔积
  for ( a <- 1 until  5 ; b <- 1 until 5){
    println(a +" "+b)
  }


  //for if 守卫模式
  for ( a <- 1 until  5 if a % 2 == 0){
    println(a )
  }


  //yield 返回新的元素
  val array = for { a <- 1 until 5} yield (a + 2)
  array.foreach(println)


  //import scala.util.control._
  //break中断循环
  val loop = new Breaks;
  loop.breakable{
    for ( a <- 1 until  5 if a % 2 == 0){
      loop.break;
      println(a )
    }
  }





}
